<CFIF lPreProcessShowMsg EQ "Yes">
<table border=0 cellpadding="1px" cellspacing=0 width="100%">
</CFIF>

<CFIF GetEntry.STAFFPID NEQ "">
	<CFSET formPID = GetEntry.STAFFPID>
<CFELSE>
	<CFSET formPID = GetEntry.PERSONNELIDNO>
</CFIF>
<CFQUERY NAME="qryCLKLVCODE" DATASOURCE=#client.company_dsn#>
	SELECT WITHBALANCE, ALLOWNEGBALANCE
	FROM CLKLVCODE
	WHERE LEAVETYPE = '#GetEntry.LEAVETYPE#'
</CFQUERY>
<CFIF GetEntry.STAFFPID NEQ "">
	<CFQUERY NAME="qryCINLEAVEAPPSM" DATASOURCE=#client.company_dsn#>
		SELECT STARTINGDATE,ENDINGDATE
		FROM CINLEAVEAPPSM
		WHERE (STARTINGDATE <= '#GetEntry.STARTINGDATE#' AND ENDINGDATE >='#GetEntry.ENDINGDATE#')
		AND STAFFPID='#formPID#' AND (APPROVED='Y' OR APPROVED='C')
	</CFQUERY>
<CFELSE>
	<CFQUERY NAME="qryCINLEAVEAPPSM" DATASOURCE=#client.company_dsn#>
		SELECT STARTINGDATE,ENDINGDATE
		FROM CINLEAVEAPPSM
		WHERE (STARTINGDATE <= '#GetEntry.STARTINGDATE#' AND ENDINGDATE >='#GetEntry.ENDINGDATE#')
		AND PERSONNELIDNO='#formPID#' AND (APPROVED='Y' OR APPROVED='C')
	</CFQUERY>
</CFIF>

<CFIF qryCINLEAVEAPPSM.RECORDCOUNT>
	<CFSET isCompareMaster= DateCompare("#qryCINLEAVEAPPSM.STARTINGDATE#", "#qryCINLEAVEAPPSM.ENDINGDATE#", "d")>
	<CFSET isCompareRecall= DateCompare("#GetEntry.STARTINGDATE#", "#GetEntry.ENDINGDATE#", "d")>

	<CFIF (isCompareMaster LTE 0 AND isCompareRecall LTE 0)>
		<CFSET isValidStartDate= DateCompare("#GetEntry.STARTINGDATE#", "#qryCINLEAVEAPPSM.STARTINGDATE#", "d")>
		<CFSET isValidEndDate= DateCompare("#qryCINLEAVEAPPSM.ENDINGDATE#", "#GetEntry.ENDINGDATE#", "d")>
	<CFELSE>
		<CFIF lPreProcessShowMsg EQ "Yes">
		<tr><td nowrap class="bold">Start Date is greater than End Date.</td></tr>
		</CFIF>
	</CFIF>
</CFIF>
<CFIF NOT qryCLKLVCODE.RecordCount>
	<CFIF lPreProcessShowMsg EQ "Yes">
	<tr><td nowrap class="bold">Leave Type not found in Lookup table.</td></tr>
	</CFIF>
<CFELSEIF NOT qryCINLEAVEAPPSM.RecordCount>
	<CFIF lPreProcessShowMsg EQ "Yes">
	<tr><td nowrap class="bold">Leave Recall is not valid.</td></tr>
	</CFIF>
<CFELSEIF Trim(Ucase(qryCLKLVCODE.WITHBALANCE)) IS "N">
	<CFIF lPreProcessShowMsg EQ "Yes">
	<tr><td nowrap class="bold">Leave Type has unlimited balance.</td></tr>
	</CFIF>
	<CFSET lPreProcessValidated="Yes">
<CFELSEIF isValidStartDate LT 0 OR isValidEndDate LT 0>
	<CFIF lPreProcessShowMsg EQ "Yes">
	<tr><td nowrap class="bold">Leave Recall is not valid. Leave being recalled is not inclusive in the applied Leave</td></tr>
	</CFIF>
<CFELSE>
	<CFQUERY NAME="qryCINLVENTITLEMENT" DATASOURCE="#client.company_dsn#">
		SELECT LEAVEENTITLEMENT, TYPE, STARTDATE, ACCRUEDBALANCE, ACCRUEDBALANCEASOF,
				LEAVEBALANCE, LEAVEBALANCEASOF, AVAILEDLEAVE, AVAILEDLEAVEASOF, LEAVETYPE
		FROM CINLVENTITLEMENT
		WHERE PERSONNELIDNO = '#formPID#' AND
			LEAVETYPE = '#GetEntry.LEAVETYPE#'
	</CFQUERY>

	<CFIF qryCINLVENTITLEMENT.RecordCount>
		<CFQUERY NAME="qryCBR201" DATASOURCE=#client.company_dsn# MAXROWS=1>
			SELECT LEAVETRACKUNIT
			FROM CBR201
		</CFQUERY>

		<CFIF qryCBR201.RecordCount>
			<!--- Check workingdayscode --->
			<CFQUERY NAME="qryCMFPA" DATASOURCE="#client.company_dsn#">
				SELECT *
				FROM CMFPA
				WHERE PERSONNELIDNO = '#formPID#'
			</CFQUERY>

			<CFQUERY NAME="qryCLKWORKINGDAYS" DATASOURCE="#client.company_dsn#">
				SELECT WORKINGHOURSPDAY,WORKINGHOURSFORLV
				FROM CLKWORKINGDAYS
				WHERE WORKINGDAYSCODE = '#qryCMFPA.WORKINGDAYSCODE#'
			</CFQUERY>

			<CFIF qryCLKWORKINGDAYS.RecordCount>
				<!--- Check if noofhours exceed noofdays --->
				<CFSET nHoursInDays=DateDiff("d", Evaluate("GetEntry.STARTINGDATE"), Evaluate("GetEntry.ENDINGDATE")) + 1>
<!---			modified by soti to be in sync with leaveprompt.cfm
				<CFSET nHoursApplied=Evaluate("GetEntry.LEAVEHOURS")>
--->

				<CFIF Trim(LCase(qryCBR201.LEAVETRACKUNIT)) IS "by day">
					<CFSET nHoursApplied = val(GetEntry.NOOFDAYS) + (val(GetEntry.LEAVEHOURS) / val(qryCLKWORKINGDAYS.WORKINGHOURSFORLV))>
				<CFELSE>
					<CFSET nHoursApplied = (val(GetEntry.NOOFDAYS) * val(qryCLKWORKINGDAYS.WORKINGHOURSFORLV)) + val(GetEntry.LEAVEHOURS)>
				</CFIF>
<!---
				<CFIF nHoursInDays GTE 0>
					<CFSET nHoursInDays=nHoursInDays + 1>
				</CFIF>
--->

				<CFIF nHoursApplied NEQ "" AND nHoursApplied NEQ 0>
					<CFIF Trim(LCase(qryCBR201.LEAVETRACKUNIT)) NEQ "by day">
						<CFSET nHoursInDays=nHoursInDays * qryCLKWORKINGDAYS.WORKINGHOURSPDAY>
					</CFIF>

					<CFIF nHoursApplied LTE nHoursInDays>
						<CFSET nLVHours=qryCINLVENTITLEMENT.LEAVEBALANCE>

						<CFIF LCase(#GetEntry.WITHPAY#) EQ "Y">
							<CFSET nLVBalance=nLVHours + nHoursApplied>
						<CFELSE>
							<CFSET nLVBalance=nLVHours>
						</CFIF>

						<CFOUTPUT>
						<CFIF lPreProcessShowMsg EQ "Yes">
						<tr>
							<!---by jepoy--->
							<td width="25%">
								<table border=0 cellpadding=2 cellspacing=0 width="100%">
								<tr>
									<td nowrap>Personnel ID No.&nbsp;</td>
									<td nowrap width="100%" class="bold">#qryCMFPA.PERSONNELIDNO#</td>
								</tr>
								<tr>
									<td nowrap>Last Name&nbsp;</td>
									<td nowrap width="100%" class="bold">#qryCMFPA.LASTNAME#</td>
								</tr>
								<tr>
									<td nowrap>First Name&nbsp;</td>
									<td nowrap width="100%" class="bold">#qryCMFPA.FIRSTNAME#</td>
								</tr>
								</table>
							</td>
							<td bgcolor="##808080"></td>
							<!---by jepoy END HERE--->
							<td width="25%">
								<table border=0 cellpadding=2 cellspacing=0 width="100%">
								<tr>
									<td nowrap>Leave Type&nbsp;</td>
									<td nowrap width="100%" class="bold">#qryCINLVENTITLEMENT.LEAVETYPE#</td>
								</tr>
								<tr>
									<td nowrap>Leave Balance as of cut-off&nbsp;</td>
									<td nowrap width="100%" class="bold">#qryCINLVENTITLEMENT.LEAVEBALANCE#</td>
								</tr>
								<tr>
									<td nowrap>Leave Balance as of&nbsp;</td>
									<td nowrap width="100%" class="bold">#DateFormat(qryCINLVENTITLEMENT.LEAVEBALANCEASOF, "mm/dd/yyyy")#</td>
								</tr>
								</table>
							</td>
							<td bgcolor="##808080"></td>
							<td width="25%">
								<table border=0 cellpadding=2 cellspacing=0 width="100%">
								<tr>
									<td nowrap>&nbsp;Type&nbsp;</td>
									<td nowrap width="100%" class="bold">#qryCINLVENTITLEMENT.TYPE#</td>
								</tr>
								<tr>
									<td nowrap>&nbsp;Entitlement&nbsp;</td>
									<td nowrap width="100%" class="bold">#qryCINLVENTITLEMENT.LEAVEENTITLEMENT#</td>
								</tr>
								<tr>
									<td nowrap>&nbsp;Start Date&nbsp;</td>
									<td nowrap width="100%" class="bold">#DateFormat(qryCINLVENTITLEMENT.STARTDATE, "mm/dd/yyyy")#</td>
								</tr>
								</table>
							</td>
							<td bgcolor="##808080"></td>
							<td width="25%">
								<table border=0 cellpadding=2 cellspacing=0 width="100%">
								<CFIF UCase(qryCINLVENTITLEMENT.TYPE) IS "EARNED">
									<tr>
										<td nowrap>&nbsp;Availed Leave&nbsp;</td>
										<td nowrap width="100%" class="bold">#qryCINLVENTITLEMENT.AVAILEDLEAVE#</td>
									</tr>
									<tr>
										<td nowrap>&nbsp;Availed Leave as of&nbsp;</td>
										<td nowrap width="100%" class="bold">#DateFormat(qryCINLVENTITLEMENT.AVAILEDLEAVEASOF, "mm/dd/yyyy")#</td>
									</tr>
								<CFELSE>
									<tr>
										<td nowrap>&nbsp;Accrued Balance&nbsp;</td>
										<td nowrap width="100%" class="bold">#qryCINLVENTITLEMENT.ACCRUEDBALANCE#</td>
									</tr>
									<tr>
										<td nowrap>&nbsp;Accrued Balance as of&nbsp;</td>
										<td nowrap width="100%" class="bold">#DateFormat(qryCINLVENTITLEMENT.ACCRUEDBALANCEASOF, "mm/dd/yyyy")#</td>
									</tr>
								</CFIF>
								<CFIF UCase(Evaluate("GetEntry.APPROVED")) NEQ "Y" OR UCase(Evaluate("GetEntry.APPROVED")) NEQ "C">
									<tr>
										<td nowrap>&nbsp;Leave Balance if Approved&nbsp;</td>
										<td nowrap width="100%" class="bold">
											#nLVBalance#
										</td>
									</tr>
								</CFIF>
								</table>
							</td>
						</tr>
						</CFIF>
						<CFSET lPreProcessValidated="Yes">

						</CFOUTPUT>
					<CFELSE>
						<CFIF lPreProcessShowMsg EQ "Yes">
						<tr><td nowrap class="bold">No. of days/hours applied exceeds No. of days.</td></tr>
						</CFIF>
					</CFIF>
				<CFELSE>
					<CFIF lPreProcessShowMsg EQ "Yes">
					<tr><td nowrap class="bold">No. of days/hours applied is 0.</td></tr>
					</CFIF>
				</CFIF>
			<CFELSE>
				<CFIF lPreProcessShowMsg EQ "Yes">
				<tr><td nowrap class="bold">Invalid WORKINGDAYSCODE.</td></tr>
				</CFIF>
			</CFIF>
		<CFELSE>
			<CFIF lPreProcessShowMsg EQ "Yes">
			<tr><td nowrap class="bold">Leave Track Unit is not properly configured.</td></tr>
			</CFIF>
		</CFIF>
	<CFELSE>
		<CFIF lPreProcessShowMsg EQ "Yes">
		<tr><td nowrap class="bold">Leave Type not found in CINLVENTITLEMENT table.</td></tr>
		</CFIF>
	</CFIF>
</CFIF>
<CFIF lPreProcessShowMsg EQ "Yes">
</table>
</CFIF>

